layui.use(['laydate','form','laypage','table','upload'], function(){
    var laydate = layui.laydate;
    var  form = layui.form,
    laypage = layui.laypage,
    upload = layui.upload,
    table = layui.table;
    ctx = $("#baseurl").val();

    //年选择器type: 'year','date','datetime'
    laydate.render({
        elem: '#year'
        ,type: 'year'
    });

    //table数据初始化
    table.render({
    elem: '#vrtable'
    ,height: 590
    ,url: $("#baseurl").val() +'/choujiang/bach_info/list_json' //数据接口
    ,parseData: function(res){ //res 即为原始返回的数据
        return {
        "code": res.code, //解析接口状态
        "msg": res.msg, //解析提示文本
        "count": res.count, //解析数据长度
        "data": res.data //解析数据列表
        };
    }
    ,page: true //开启分页
    , where: { //传参数
            //"orgId": $("#orgId option:selected").val(),
            //"counterpartyName": $("#counterpartyId option:selected").text()
            "bachId": $("#bachId").val(),//id
            "backNo": $("#backNo").val(),//批次号
    }
    ,request: {
        pageName: 'current' //页码的参数名称，默认：page
        ,limitName: 'size' //每页数据量的参数名，默认：limit
    }
    ,limits:[10,20,30,40,50,100,150,200,300]
    ,id: 'bachIdtb'//设定容器唯一ID。该参数等价于<table id="test"></table>中的 id 值。id值是对表格的数据操作方法上是必要的传递条件，它是表格容器的索引
    ,cols: [[ //表头
            {field: 'bh', title: '序号', width:50,type: 'numbers'}
            ,{field: 'bachId', title: 'id', sort: true, width:150}
            ,{field: 'backNo', title: '批次号', sort: true, width:150}
            ,{field: 'signup_mark', title: '操作', width: 100,templet:'#my_operation'}
        ]]
    //如果使用合计数，请放开下面代码修改，然后把值写上去td[data-field="itemNo" 定义在哪个列后显示
    /*,done: function(res, curr, count){
        this.elem.next().find('.layui-table-total td[data-field="budgetAmount"] .layui-table-cell').text(res.budgetInfo.budgetAmount.toFixed(2));
        this.elem.next().find('.layui-table-total td[data-field="finallBudgetAmount"] .layui-table-cell').text(res.budgetInfo.finallBudgetAmount.toFixed(2));
        this.elem.next().find('.layui-table-total td[data-field="surplusBudgetAmount"] .layui-table-cell').text(res.budgetInfo.surplusBudgetAmount.toFixed(2));
    }*/
    });

    //导出
    $("#export").click(function () {
        $("#_bachId").val($("#bachId").val()); //id
        $("#_backNo").val($("#backNo").val()); //批次号
        //$("#_tradeAccountId").val($("#tradeAccountId option:selected").val());//下拉框请放开此项进行修改
        $("#reportsub").submit();
    });


});

/*删除*/
function member_del(obj,id){
    layer.confirm('确认要删除吗？',function(index){
        //发异步删除数据
        $.ajax({
        url: $("#baseurl").val() + '/choujiang/bach_info/del',
        data:  "bachId="+id,           type: 'post',
        success: function (data) {
            console.log(data);
            //发异步，把数据提交给php
            layer.alert("删除成功", {icon: 6},function () {
                $(obj).parents("tr").remove();
                layer.msg('已删除!',{icon:1,time:1000});
                window.location.reload();
            });
            //return false;
            }
        });

    });
}
